Ex007, Y2K counter
This is an small program to calculate distance between year 2000 and current date
and time.
Exercise 007: Y2K counter:
1. Drop a Label and name it 'laY2K'.
2. Drop a timer and write this procedure at OnTimer event:
var
Y2K: TDateTime;
Period: TDateTime;
Days, Hours, Minuts, Seconds: word;
Msg: string;
begin
Y2K:= EncodeDate(2000, 1, 1) + EncodeTime(0, 0, 0, 0);
Period:= Y2K-Now;
if Period < 0 then // Y2K already passed
begin
Period:= Abs(Period);
Msg:= 'Passed since Y2K';
end
else
Msg:= 'Remaining to Y2K'; // Y2K remaining time
Days:= Trunc(Period);
Period:= Period - Days;
Hours:= Trunc(Period * 24);
Period:= Period - Hours/24;
Minuts:= Trunc(Period * 24 * 60);
Period:= Period - Minuts/(24*60);
Seconds:= Trunc(Period * 24 * 60 * 60);
laY2K.Caption:= Format(' %d Days, %d:%d:%d, %s',
[Days, Hours, Minuts, Seconds, Msg]);
See also:
Date and time routines
Ex003: Timer